package org.hjl.commonutils.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.hjl.commonutils.annotation.Power;
import org.hjl.commonutils.date.DateUtil;
import org.hjl.commonutils.exception.GlobalException;
import org.hjl.commonutils.string.StringUtil;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author hjl
 * @version 1.0
 * @since 2024-08-20 11:34
 */
@Component
@Aspect
public class CommonAroundAop {

    private static final List<String> POWER_LIST = List.of("log");

    @Pointcut("execution(* org.hjl.commonutils.controller.AopController.*(..))")
    public void pointcut() {
    }

    @Before("pointcut()")
    public void beforeLog(JoinPoint point) {
        // 获取方法上注解
        MethodSignature methodSignature = (MethodSignature) point.getSignature();
        Method method = methodSignature.getMethod();
        // 获取鉴权注解
        Power annotation = method.getAnnotation(Power.class);
        if (annotation != null) {
            System.out.println("权限：" + annotation.value());
            if (POWER_LIST.contains(annotation.value())) {
                throw new GlobalException("无权限，禁止操作！");
            }
        }
    }


}
